//package com.ugoodtech.mdcc.client;
//
//import com.ugoodtech.mdcc.client.controller.MyWebSocket;
//import org.json.JSONObject;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.servlet.HandlerInterceptor;
//import org.springframework.web.servlet.ModelAndView;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.text.SimpleDateFormat;
//import java.util.*;
//
///**
// * Created with IntelliJ IDEA.
// * User: Kotone
// * Date: 2017/9/28
// * Time: 19:09
// * To change this template use File | Settings | File Templates.
// */
//public class AddLogInterceptor implements HandlerInterceptor {
//
//
//    @Autowired
//    private MyWebSocket myWebSocket;
//
//    @Override
//    public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception {
//        String uuid= UUID.randomUUID().toString();
//        httpServletRequest.setAttribute("AddLogInterceptor-uuid",uuid);
//        try {
//            if(logger.isDebugEnabled()){
//                Map map = new HashMap();
//                SimpleDateFormat simpleDateFormat=new SimpleDateFormat();
//                map.put("日期:",simpleDateFormat.format(new Date()));
//                map.put("url:",httpServletRequest.getRequestURI());
////                map.put("url:",httpServletRequest.getRequestURL());
//                Map paramMap = new HashMap();
//                Enumeration paramNames = httpServletRequest.getParameterNames();
//                while (paramNames.hasMoreElements()) {
//                    String paramName = (String) paramNames.nextElement();
//
//                    String[] paramValues = httpServletRequest.getParameterValues(paramName);
//                    if (paramValues.length == 1) {
//                        String paramValue = paramValues[0];
//                        if (paramValue.length() != 0) {
//                            paramMap.put(paramName, paramValue);
//                        }
//                    }
//                }
//                map.put("参数",paramMap);
//                Map headerMap = new HashMap();
//                Enumeration headerNames = httpServletRequest.getHeaderNames();
//                while (headerNames.hasMoreElements()) {
//                    String headerName = (String) headerNames.nextElement();
//                    String headerValues = httpServletRequest.getHeader(headerName);
//                    headerMap.put(headerName, headerValues);
//                }
//                map.put("请求header",headerMap);
//                map.put("请求结果状态", httpServletResponse.getStatus());
//                map.put("uuid", uuid);
//                JSONObject jsonObject=new JSONObject(map);
//                logger.debug(jsonObject.toString()+"\r");
//                myWebSocket.sendInfo(jsonObject.toString());
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return true;
//
//    }
//
//    @Override
//    public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {
//
//    }
//
//    @Override
//    public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {
//
//    }
//
//    Logger logger = LoggerFactory.getLogger(AddLogInterceptor.class);
//}
